#!/bin/bash

# 要统计的文件夹列表
folders=("bsp_drivers" "lora_protocol" "legacy" "modbus" "screen" "soe_about" "squareLine/components" "squareLine/screens")
# 文件扩展名，通常源码文件以这些扩展名结尾
file_extensions=("*.c" "*.cc" "*.h" "*.cpp" "*.py" "*.java" "*.sh" "*.js" "*.txt")

# 统计总行数
total_lines=0

# 遍历每个文件夹
for folder in "${folders[@]}"; do
    if [ -d "$folder" ]; then
        echo "统计文件夹：$folder"

        # 初始化文件夹行数
        folder_lines=0
        
        # 遍历文件夹中的每种文件类型
        for ext in "${file_extensions[@]}"; do
            # 查找文件并统计行数，避免重复统计
            lines=$(find "$folder" -type f -name "$ext" -print0 | xargs -0 cat | wc -l)
            if [ -n "$lines" ]; then
                echo "$ext 文件行数: $lines"
                folder_lines=$((folder_lines + lines))
            fi
        done

        echo "文件夹 $folder 行数: $folder_lines"
        total_lines=$((total_lines + folder_lines))
    else
        echo "警告: 文件夹 $folder 不存在！"
    fi
done

# 打印总行数
echo "总行数: $total_lines"
